package com.lagou.filter;

import com.lagou.filter.component.IpAddressThreadLocal;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.Filter;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.dubbo.rpc.RpcException;
import org.apache.dubbo.rpc.support.RpcUtils;


@Activate(group = {CommonConstants.CONSUMER})
public class TransportIPFilter implements Filter {

  @Override
  public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
    String ipAddress = IpAddressThreadLocal.getInstance().getIpAddress();
    RpcContext.getContext().setAttachment("clientIp", ipAddress);
    return invoker.invoke(invocation);
  }
}
